<template>
  <div>
    <el-dialog
      title="发放奖品"
      v-model="dialogVisible"
      width="600px"
      @close="dialogFormVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form size="small" ref="form" :model="form">
        <el-form-item label="收件人" :label-width="formLabelWidth">
          {{ model.name }}
        </el-form-item>
        <el-form-item label="收件电话" :label-width="formLabelWidth">
          {{ model.phone }}
        </el-form-item>
        <el-form-item label="收件地址" :label-width="formLabelWidth">
          {{ model.address }}
        </el-form-item>
        <el-form-item
          label="物流公司"
          :label-width="formLabelWidth"
          :rules="[{ required: true, message: ' ' }]"
        >
          <el-select size="small" v-model="form.expressId" placeholder="请选择">
            <el-option
              v-for="(item, index) in expressList"
              :key="index"
              :label="item.expressName"
              :value="item.expressId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="物流单号"
          :label-width="formLabelWidth"
          prop="expressNo"
          :rules="[{ required: true, message: ' ' }]"
        >
          <el-input
            type="textarea"
            v-model="form.expressNo"
            placeholder="请输入物流单号"
          ></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialogFormVisible(false)">取 消</el-button>
          <el-button type="primary" @click="submit" :loading="loading"
            >确 定</el-button
          >
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script>
import LotteryApi from "@/api/lottery.js";
export default {
  components: {},
  data() {
    return {
      loading: false,
      /*左边长度*/
      formLabelWidth: "120px",
      /*是否显示*/
      dialogVisible: false,
      form: {
        expressId: "",
        expressNo: "",
      },
    };
  },
  props: ["open_send", "model", "expressList"],
  created() {
    this.dialogVisible = this.open_send;
  },
  methods: {
    /*处理*/
    submit() {
      let self = this;
      let form = self.form;
      form.recordId = self.model.recordId;
      self.$refs.form.validate((valid) => {
        if (valid) {
          self.loading = true;
          LotteryApi.send(form, true)
            .then((data) => {
              self.loading = false;
              ElMessage({
                message: data.msg,
                type: "success",
              });
              self.dialogFormVisible(true);
            })
            .catch((error) => {
              self.loading = false;
            });
        }
      });
    },
    /*关闭弹窗*/
    dialogFormVisible(e) {
      if (e) {
        this.$emit("closeDialog", {
          type: "success",
          openDialog: false,
        });
      } else {
        this.$emit("closeDialog", {
          type: "error",
          openDialog: false,
        });
      }
    },
  },
};
</script>
<style></style>
